/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __X_ATOMIC_H__
#define __X_ATOMIC_H__

/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
/* includes (local) ----------------------------------------------------------*/
#include "x_compiler.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/

typedef struct {
    volatile int val;
} atomic_int;

typedef struct {
    volatile unsigned int val;
} atomic_uint;

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/

/**
 * atomic_int_get - get the value of an atomic_int variable
 * @a: address of the atomic_int variable
 *
 * return: value of the atomic_int variable
 */
static __always_inline int atomic_int_get(atomic_int *a)
{
    return a->val;
}

/**
 * atomic_uint_get - get the value of an atomic_uint variable
 * @a: address of the atomic_uint variable
 *
 * return: value of the atomic_uint variable
 */
static __always_inline unsigned int atomic_uint_get(atomic_uint *a)
{
    return a->val;
}

/**
 * atomic_int_set - set the value of an atomic_int variable
 * @a: address of the atomic_int variable
 *
 * return: NA
 */
static __always_inline void atomic_int_set(atomic_int *a, int v)
{
    a->val = v;
}

/**
 * atomic_uint_set - set the value of an atomic_uint variable
 * @a: address of the atomic_int variable
 *
 * return: NA
 */
static __always_inline void atomic_uint_set(atomic_uint *a, unsigned int v)
{
    a->val = v;
}

/* externs -------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __X_ATOMIC_H__ */
